require(["common", "jQuery","coAjax",'./js/tools/getarea.js'], function(jSouper,$,coAjax) {
	coAjax.get(appConfig.user.address_detail,function (result) {
		App.set("user.address_detail",result.result);
	});
	App.set("$Event.add_user_address",function () {
		var new_user_address = {
			province:$("[name='province']").find('option:selected').text(),
			town:$("[name='city']").val(),
			county:$("[name='area']").val(),
			// street:
			detail:$("[name='detailed_addre']").val(),
			mobilenumber:$("[name='mobile_num']").val(),
			phonenumber:$("[name='phone_num']").val(),
			postcode:$("[name='zip_code']").val(),
			name:$("[name='name']").val()
		};
		console.log(new_user_address);
		coAjax.post(appConfig.user.add_address,new_user_address,function (result) {
			var address_detail = App.get("user.address_detail");
			address_detail.unshift(result.result);
			App.set("user.address_detail",address_detail);
		},function (errorCode,xhr,errorMsg) {
			alert("error",errorMsg);
		});
	},function (errorCode,xhr,errorMsg) {
		alert("error",errorMsg);
	});
	App.set("$Event.user.set_default_address",function (e,vm) {
		coAjax.put(appConfig.user.set_default_address,{
			address_id:vm.get("_id")
		},function (result) {
			App.set("loginer.default_ua_id",result.result);
			App.getModel().touchOff("user.address_detail")
		})
	},function (errorCode,xhr,errorMsg) {
		alert("error",errorMsg);
	});
	App.set("$Top.$Event.user.remove_address",function (e,vm) {
		coAjax["delete"](appConfig.user.remove_address,{
			address_id:vm.get("_id")
		},function (result) {
			App.set("user.address_detail",result.result);
		})
	},function (errorCode,xhr,errorMsg) {
		alert("error",errorMsg);
	});
})